package com.huadi.firematerialident.service;

import com.huadi.firematerialident.dao.ApplicationDaoImpl;
import com.huadi.firematerialident.po.Application;
import com.huadi.firematerialident.po.Review;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ApplicationServiceImpl implements ApplicationService{

    @Autowired
    ApplicationDaoImpl applicationDao;
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    NormalUserServiceImpl normalUserService;

    @Override
    public int addApplication(Application application) {
        return applicationDao.addApplication(application);
    }

    @Override
    public int updateApplication(Application application) {
        return applicationDao.updateApplication(application);
    }

    @Override
    public int deleteApplicationByID(String applicationID) {
        return applicationDao.deleteApplicationByID(applicationID);
    }

    @Override
    public List<Map<String,Object>> selectApplicationByID(String applicationID) {
        return applicationDao.selectApplicationByID(applicationID);
    }

    @Override
    public List<Map<String,Object>> getAllApplication() {
        return applicationDao.getAllApplication();
    }

    @Override
    public List<Map<String, Object>> getMyApplication() {
        String sql="select * from application where NUserID=?";
        return jdbcTemplate.queryForList(sql,normalUserService.getNUserID());
    }

    @Override
    public List<Map<String,Object>> getIdentified(){
        String sql="select * from application where NUserID=? and ArchivingStatus='是'";
        return jdbcTemplate.queryForList(sql,normalUserService.getNUserID());
    }

    @Override
    public Application selectApplicationByID_class(String id){
        List<Map<String ,Object>> list = applicationDao.selectApplicationByID(id);
        Application application = new Application();
        application.setAppID((String) list.get(0).get("AppID"));
        application.setMEID((String) list.get(0).get("MEID"));
        application.setNUserID((String) list.get(0).get("NUserID"));
        application.setInspectionUnitName((String) list.get(0).get("InspectionUnitName"));
        application.setInspectionUnitAdd((String) list.get(0).get("InspectionUnitAdd"));
        application.setAppDate((LocalDateTime) list.get(0).get("AppDate"));
        application.setArchivingStatus((String) list.get(0).get("ArchivingStatus"));
        application.setLogicalAddDel((boolean) list.get(0).get("LogicalAddDel"));
        application.setLastModification((LocalDateTime) list.get(0).get("LastModification"));
        return application;
    }
}
